<?php
namespace Tyrone\Command;
use Medoo\Medoo;
use Tyrone\Model\Game\LogLogin;
use Swoole\Coroutine;
use Tyrone\Model\Game\PayLog;
use Tyrone\Model\PlayerPay;

class RoleDayLoginInfo extends Base
{



    public  function execute()
    {
        ini_set('memory_limit', '1G');
        $datas = [];
        $database = $this->database;
        $game_database = $this->game_mysql;
        $mysql = $this->mysql;
        $redis = $this->redis;
        $this->setFrequency(300);
        $tday = $day = date("Ymd",strtotime($this->sDate));
        $eDate = date("Ymd",strtotime($this->eDate));

        $logLoginModel = new LogLogin($game_database);
        $playerOnlineModel = new \Tyrone\Model\PlayerOnline($mysql);

        while($day <= $eDate) {
            //统计登录数据
            $data = $logLoginModel->getLoginInfo($day);

            foreach($data as $vo){
                $save = $vo;
                $save["day"] = $day;
                $save['plat_server'] = $this->plat_server;
                $save["month"] = date("Ym", strtotime($vo["day"]));
                //保证字段一致
                $save["is_new"] = 0;
                //当天注册
                if(date("Ymd", $vo["reg_time"]) == $day){
                    $save["is_new"] = 1;
                }
                unset($save["reg_time"]);
                $datas[] = $save;
            }

            $day = date('Ymd',strtotime($day) + 86400);
        }
        foreach (array_chunk($datas,1000) as $items){
            $playerOnlineModel->updateData($items);
            usleep(100);
        }
        /*$id = UNIQUE_KEY;
        while($tday <= $eDate) {
            $redis->hset($id.'_roleLoginInfo',$this->platform.'_'.$this->plat_server,$tday);
            $tday = date('Ymd',strtotime($tday) + 86400);
        }*/


        return $this->result([count($datas)]);
    }
}